package com.project.controller;

import com.project.bean.StudentBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author lyl
 * description:
 */
@Controller
@RequestMapping("test")
public class TestController {

    @RequestMapping("show")
    public String show(HttpServletRequest request) {
        //在request中绑定共享对象，作用范围为一次请求范围内
        request.setAttribute("name", "tom");
        request.setAttribute("student", new StudentBean(1, "测试学生", 90));

        List<StudentBean> studentList = List.of(new StudentBean(1, "测试学生", 90),
                new StudentBean(2, "测试学生2", 56),
                new StudentBean(3, "测试学生3", 78),
                new StudentBean(4, "测试学生4", 89),
                new StudentBean(5, "测试学生5", 61));
        request.setAttribute("studentList", studentList);

        //请求转发方式：
        return "/html/index.html";
        //重定向方式，最终url网址栏会发生变动
//        return "redirect:http://www.bilibili.com";
    }

}
